package org.msfj.admin.org.controller;

import org.msfj.admin.model.Dept;
import org.msfj.admin.vo.DeptVo;
import org.msfj.admin.model.Dept;
import org.msfj.admin.vo.DeptVo;
import org.msfj.admin.model.Dept;
import org.msfj.admin.vo.DeptVo;
import org.msfj.admin.org.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CascaderResult;
import org.msfj.common.model.CommonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 系统部门信息controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2017-08-10 17:30:20
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "系统部门信息接口", tags = "系统部门信息接口")
@RestController
@RequestMapping("org/dept")
public class DeptController extends BaseController{

    @Autowired
    private DeptService deptService;

    /**
     * 添加系统部门信息
     *
     * @param deptVo
     * @return CommonResult.ok(DeptVo)
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加系统部门信息",notes = "添加系统部门信息")
    @ApiImplicitParam(value = "deptVo",name = "deptVo",dataType = "org.msfj.admin.vo.DeptVo",paramType = "query")
    public CommonResult addDept(DeptVo deptVo){
        Dept dept = deptService.saveOrEdit(deptVo);
        return CommonResult.ok(deptService.setOtherProperties(dept));
    }

    /**
     * 修改系统部门信息
     *
     * @param deptVo
     * @return CommonResult.ok(DeptVo)
     */
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改系统部门信息",notes = "修改系统部门信息")
    @ApiImplicitParam(value = "deptVo",name = "deptVo",dataType = "org.msfj.admin.vo.DeptVo",paramType = "query")
    public CommonResult editDept(DeptVo deptVo){
        Dept dept = deptService.saveOrEdit(deptVo);
        return CommonResult.ok(deptService.setOtherProperties(dept));
    }

    /**
     * 逻辑删除系统部门信息
     *
     * @param deptVo
     * @return CommonResult.ok(DeptVo)
     */
    @PostMapping("/del")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统部门信息",notes = "逻辑删除系统部门信息")
    @ApiImplicitParam(value = "deptVo",name = "deptVo",dataType = "org.msfj.admin.vo.DeptVo",paramType = "query")
    public CommonResult delDept(DeptVo deptVo){
        Dept dept = deptService.delById(deptVo);
        return CommonResult.ok(deptService.setOtherProperties(dept));
    }

    /**
     * 逻辑删除系统用户信息
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统部门信息",notes = "逻辑删除系统部门信息")
    @ApiImplicitParam(value = "ids",name = "ids",dataType = "java.util.List",paramType = "query")
    public CommonResult delUsers(@RequestParam("ids[]") List<String> ids){
        Dept dept = new Dept();
        deptService.delByIds(ids, dept);
        return CommonResult.ok();
    }

    /**
     * 真实删除系统部门信息
     *
     * @param deptVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "真实删除系统部门信息",notes = "真实删除系统部门信息")
    @ApiImplicitParam(value = "deptVo",name = "deptVo",dataType = "org.msfj.admin.vo.DeptVo",paramType = "query")
    public CommonResult deleteDept(DeptVo deptVo){
        deptService.trueDelById(deptVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找系统部门信息
     *
     * @param deptVo
     * @return CommonResult.ok(DeptVo)
     */
    @GetMapping("/get")
    @ResponseBody
    @ApiOperation(value = "根据id查找系统部门信息",notes = "根据id查找系统部门信息")
    @ApiImplicitParam(value = "deptVo",name = "deptVo",dataType = "org.msfj.admin.vo.DeptVo",paramType = "query")
    public CommonResult getDept(DeptVo deptVo){
        Dept dept = deptService.getById(deptVo.getId());
        return CommonResult.ok(deptService.setOtherProperties(dept));
    }

    /**
     * 根据翻页参数、搜索参数查找系统部门信息
     *
     * @param deptVo
     * @param page 当前第几页
     * @param rows 每页多少条记录
     * @return CommonResult.ok(PageInfo<DeptVo>)
     */
    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "根据翻页参数、搜索参数查找系统部门信息",notes = "根据翻页参数、搜索参数查找系统部门信息")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "deptVo",name = "deptVo",dataType = "org.msfj.admin.vo.DeptVo",paramType = "query"),
        @ApiImplicitParam(name = "page",value = "page",dataType = "Integer",paramType = "path"),
        @ApiImplicitParam(name = "rows",value = "rows",dataType = "Integer",paramType = "path")
    })
    public CommonResult findDeptList(DeptVo deptVo, Integer page, Integer rows){
        PageInfo<DeptVo> deptVoPageInfo = deptService.getByDept(deptVo,page,rows);
        return CommonResult.ok(deptVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有系统部门信息
     *
     * @param deptVo
     * @return CommonResult.ok(List<DeptVo>)
     */
    @GetMapping("/getAll")
    @ResponseBody
    @ApiOperation(value = "根据搜索参数查找所有系统部门信息",notes = "根据搜索参数查找所有系统部门信息")
    @ApiImplicitParam(value = "deptVo",name = "deptVo",dataType = "org.msfj.admin.vo.DeptVo",paramType = "query")
    public CommonResult getAllDept(DeptVo deptVo){
        List<DeptVo> deptVoList = deptService.getAllDept(deptVo);
        return CommonResult.ok(deptVoList);
    }

    /**
     * 获取系统部门信息Tree对象
     *
     * @return CommonResult.ok(List<DeptVo>)
     */
    @GetMapping("/getTree")
    @ResponseBody
    @ApiOperation(value = "获取系统部门信息Tree对象", notes = "获取系统部门信息Tree对象")
    public CommonResult getDeptTree() {
        List<DeptVo> deptVos = deptService.getDeptTree();
        return CommonResult.ok(deptVos);
    }

    /**
     * 获取系统部门信息级联对象
     *
     * @param id  不可选的id
     * @return CommonResult.ok(List<CascaderResult>)
     */
    @GetMapping("/getCascader")
    @ResponseBody
    @ApiOperation(value = "获取系统部门信息级联对象", notes = "获取系统部门信息级联对象")
    @ApiImplicitParam(value = "id", name = "id", dataType = "java.lang.Long", paramType = "query")
    public CommonResult getCascader(String id) {
        List<DeptVo> deptVos = deptService.getDeptTree();
        List<CascaderResult> cascaderResults = CascaderResult.getCascaderResult("Id", "Name", "TreePosition", id, deptVos);
        return CommonResult.ok(cascaderResults);
    }
}
